home *** CD-ROM | disk | FTP | other *** search
- #include <QuickDraw.h>
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <Processes.h>
- #include <TextEdit.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Memory.h>
- #include <Errors.h>
- #include <ToolUtils.h>
-
-
- #ifdef __powerc
- QDGlobals qd;
- #endif
-
-
-
- void InitApplication(void);
- void CreateNewWindow(void);
- void MainEventLoop(void);
- void MenuCommand(long whaHappened);
- void DoAboutBox(void);
-
- void PreEventLoop(void);
- void PostEventLoop(void);
- pascal void DrawWindowContent(short, short, GDHandle, long);
- void DrawIt(WindowPtr win);
- void DoUpdate(WindowPtr thisWindow);
-
-
- void DragWindowGrid(WindowPtr win, Point pt);
-
-
- static Boolean gDone;
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void main()
- {
-
- InitApplication();
- PreEventLoop();
- MainEventLoop();
- }
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void InitApplication()
- {
- Handle theMenu;
-
- // Toolbox initialization
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(0,everyEvent);
-
- // Application initialization
- gDone = false;
-
- theMenu = GetNewMBar(128);
- if ( theMenu == nil )
- goto MenuStuffFailed;
-
- SetMenuBar(theMenu);
- AddResMenu(GetMHandle(128), 'DRVR');
- DrawMenuBar();
-
- return;
-
- MenuStuffFailed:
- // If the menu stuff failed, something just ain't right (most likely some
- // resources are missing.
- gDone = true;
- return;
-
- }
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void DoAboutBox()
- {
- (void) Alert(128, nil);
- }
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void MainEventLoop()
- {
- EventRecord theEvent;
- WindowPtr thisWindow;
- short clickArea;
- long menuResult;
- char charCode;
-
- while ( !gDone )
- {
- if ( WaitNextEvent(everyEvent, &theEvent, 0, nil) )
- {
- switch (theEvent.what)
- {
- case mouseDown:
- clickArea = FindWindow(theEvent.where, &thisWindow);
-
- if (clickArea == inDrag)
- {
- DragWindowGrid(thisWindow, theEvent.where);
- }
- else if ( clickArea == inContent )
- {
- if ( thisWindow != FrontWindow() )
- SelectWindow(thisWindow);
- }
- else if (clickArea == inGoAway)
- {
- if ( TrackGoAway(thisWindow, theEvent.where) )
- gDone = true;
- }
- else if ( clickArea == inMenuBar )
- {
- menuResult = MenuSelect(theEvent.where);
- if ( (menuResult >> 16) != 0 )
- {
- MenuCommand(menuResult);
- HiliteMenu(0);
- }
- }
- break;
- case keyDown:
- charCode = theEvent.message & charCodeMask;
-
- if ( (theEvent.modifiers & cmdKey) != 0 )
- {
- menuResult = MenuKey(charCode);
-
- if ( (menuResult >> 16) != 0 )
- MenuCommand(menuResult);
-
- }
- break;
- case updateEvt:
- thisWindow = (WindowPtr)theEvent.message;
- DoUpdate(thisWindow);
-
- break;
-
- }
- }
- }
- }
-
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void MenuCommand(long whaHappened)
- {
- short menuID, menuItem;
-
- menuID = (whaHappened >> 16);
- menuItem = (whaHappened & 0xFFFF);
-
- if ( menuID == 128 )
- {
- if ( menuItem == 1)
- DoAboutBox();
- }
- else if ( menuID == 129 )
- {
- if (menuItem == 1)
- gDone = true;
- }
- }
-
-